﻿using System;
using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.UI
{
    public class Portal
    {
        public static GlobalControl gc = new GlobalControl();

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        private static void Main()
        {
            //DateTime dtEnd = Convert.ToDateTime("6/1/2009");
            //if (DateTime.Now.CompareTo(dtEnd) > 0)
            //{
            //    string message = "使用期限已到，请联系作者wuhuacong@163.com";
            //    LogHelper.Error(message);
            //    MessageUtil.ShowError(message);
            //    Application.Exit();
            //    return;
            //}

            SetUIConstants();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //登陆界面
            //FrmRoomStatusView tt = new FrmRoomStatusView();
            //tt.StartPosition = FormStartPosition.CenterScreen;
            //tt.ShowDialog();
            //return;

            Logon dlg = new Logon();
            dlg.StartPosition = FormStartPosition.CenterScreen;
            if (DialogResult.OK == dlg.ShowDialog())
            {
                if (dlg.bLogin)
                {
                    SplashScreen.Splasher.Show(typeof(SplashScreen.frmSplash));

                    gc.MainDialog = new MainForm();
                    gc.MainDialog.StartPosition = FormStartPosition.CenterScreen;

                    //gc.MainDialog.ShowInTaskbar = true;
                    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                    Application.Run(gc.MainDialog);
                }
                
            }
            dlg.Dispose();
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs ex)
        {
            LogHelper.Error(ex.Exception);

            string message = string.Format("{0}\r\n操作发生错误，您需要退出系统么？", ex.Exception.Message);
            if (DialogResult.Yes == MessageUtil.ShowYesNoAndError(message))
            {
                Application.Exit();
            }
        }

        private static void SetUIConstants()
        {
            string expiredDate = "12/29/2011";
            string softName = "HotelMis";
            string version = "4.0";
            string publicKey = "<RSAKeyValue><Modulus>v6VAXC8onYpFnnPEdc7qRlGtZFnf9H7FVXcD6pLpB3TQxClt+h6EFieUz4SHZIPM7Y1iwlCKAySMVAfKpy7VCTmvJz5XOcFtLoilqOn5WAJC4A7y5Y2s0VDRaIIX7IEAcEhG9Gj+5JTWzgeRKOHMuN6nVynlR1y0XC3pT7uBSX0=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
            UIConstants.SetValue(expiredDate, version, softName, publicKey);

            //代码设置授权码
            WHC.Security.MyConstants.License = "397cV0hDLlNlY3VybXR5fOS8jeWNjuiBqnzlua-lt57niLHlkK-o_6rmioDmnK-mnInpmZDlhbzlj7h8RmFsc2Uv";
           // WHC.Dictionary.MyConstants.License = "37c6V0hDLkRpY3Rpa25hcnl85LyN5Y2O6IGqfOW5_*W3nueIseWQr*i-qubKgObcr*bciemZkOWFrOWPuHxGYWxzZQvv";
            WHC.Pager.WinControl.MyConstants.License = "070eV0hDLlBhZ2VyfOS8jeWNjuiBqnx8RmFsc2Uv";
        }
    }
}
